package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;


    //查询供应商列表
    @Override
    public List<Supplier> selectList(Integer page, Integer rows, String supplierName) {
        page=(page-1)*rows;
        List<Supplier> list = supplierDao.selectList(page,rows,supplierName);
        return list;
    }
    //新增或修改供应商
    @Override
    public void saveOrUpdate(Supplier supplier,String supplierId) {
        if (!StringUtils.isEmpty(supplierId)){
            supplier.setSupplierId(Integer.parseInt(supplierId));
            supplierDao.update(supplier);
        }else {
            supplierDao.save(supplier);
        }

    }
    //删除
    @Override
    public Boolean delete(String ids) {
        String[] split = ids.split(",");
        boolean flag = supplierDao.delete(split);
        return flag;
    }
}
